package com.soecode.lyf.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.PostConstruct;

/**
 * @author: chenhs
 * @date: Created in 22:08 2020/2/26
 **/
@EnableWebMvc
@EnableSwagger2
@Configuration
public class SwaggerConfig {

    @PostConstruct
    public void postConstruct() {
        System.err.println("-------------->启用SwaggerUI");
    }

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                //.apis(RequestHandlerSelectors.basePackage("com.soecode.lyf.web"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口列表 v1.0")
                .contact(new Contact("chenhs", "http://www.chenhs.com", "hson08_chen@163.com"))
                .termsOfServiceUrl("http://localhost:8080/ssm/swagger-ui.html")
                .description("接口测试")
                .version("1.0")
                .build();
    }

}